#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : project
@File : xy-xy_toos.py
@Author : 飞宇
@Time : 2025/9/9 19:35  
@脚本说明 : 
"""
import argparse

# 假设这些模块已存在并正确导入
from tools.mysql_val import mysql_run
from tools.redis_val import redis_run
from tools.ssh_val import ssh_run
from tools.ip_val import run_ip
from tools.Subdomain import run_subdomain
from tools.port_a_val import scan_port_a_run
from tools.port_h_val import scan_port_h_run
from tools.ccolor import Colors

banner = """
                                                             
8b,     ,d8  8b       d8  ,adPPYba,   ,adPPYba,  ,adPPYYba,  8b,dPPYba,   
 `Y8, ,8P'   `8b     d8'  I8[    ""  a8"     ""  ""     `Y8  88P'   `"8a  
   )888(      `8b   d8'    `"Y8ba,   8b          ,adPPPPP88  88       88  
 ,d8" "8b,     `8b,d8'    aa    ]8I  "8a,   ,aa  88,    ,88  88       88  
8P'     `Y8      Y88'     `"YbbdP"'   `"Ybbd8"'  `"8bbdP"Y8  88       88  
                 d8'                                                      
                d8'                                                                                                                                                                                         
"""
print(f"{Colors.BLUE_BRIGHT}{Colors.BOLD}{banner}{Colors.RESET}")
# 创建命令行解析器对象
parser = argparse.ArgumentParser(description="xy-scan")
subparsers = parser.add_subparsers(help="选择要使用的功能", dest="sub_command")

# 创建MySQL的解析器对象
mysql_subparsers = subparsers.add_parser("mysql", help="MySQL相关漏扫")
mysql_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="MySQL主机地址")
mysql_subparsers.add_argument("--port", "-P", dest="port", type=int, default=3306, help="MySQL端口号")
mysql_subparsers.add_argument("--username", "-u", dest="username", type=argparse.FileType(mode='r', encoding="utf-8"), default="./dict/user.dict", help="MySQL用户名")
mysql_subparsers.add_argument("--password", "-p", dest="password", type=argparse.FileType(mode='r', encoding="utf-8"), default="./dict/passwd.dict", help="MySQL密码本")

# 创建Redis的解析器对象
redis_subparsers = subparsers.add_parser("redis", help="Redis相关漏扫")
redis_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="Redis主机地址")
redis_subparsers.add_argument("--port", "-P", dest="port", type=int, default=6379, help="Redis端口号")
redis_subparsers.add_argument("--password", "-p", dest="password", type=argparse.FileType(mode='r', encoding="utf-8"), default="./dict/passwd.dict", help="Redis密码本")

# 创建IP的解析器对象
ip_subparsers = subparsers.add_parser("ip", help="主机相关漏扫")
ip_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="IP主机地址网段")
ip_subparsers.add_argument("--iface", "-f", dest="iface", type=str, default="以太网", help="扫描网卡")

# 创建全端口的解析器对象
port_subparsers = subparsers.add_parser("port_a", help="全端口扫描")
port_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="端口扫描主机地址")
port_subparsers.add_argument("--sep", "-s", dest="sep", type=int, default=10, help="端口扫描间隔")

# 创建精简端口的解析器对象
port_h_subparsers = subparsers.add_parser("port_h", help="精简端口扫描")
port_h_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="端口扫描主机地址")

# 创建SSH的解析器对象
ssh_subparsers = subparsers.add_parser("ssh", help="SSH密码爆破")
ssh_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="SSH主机地址")
ssh_subparsers.add_argument("--port", "-P", dest="port", type=int, default=22, help="SSH端口号")
ssh_subparsers.add_argument("--username", "-N", dest="username", type=str, default="", help="用户名字")
# ssh_subparsers.add_argument("--username", "-U", dest="username", type=argparse.FileType(mode='r', encoding="utf-8"), default="./dict/user.dict", help="SSH用户名")
ssh_subparsers.add_argument("--password", "-S", dest="password", type=argparse.FileType(mode='r', encoding="utf-8"), default="./dict/passwd.dict", help="SSH密码本")

#创建子域名的解析器对象
subdomain_subparsers = subparsers.add_parser("subdomain", help="子域名扫描")
subdomain_subparsers.add_argument("--subdomain", "-D", dest="domain", type=str, default="", help="输入主域名")


args = parser.parse_args()

if args.sub_command == "mysql":
    mysql_run(args.host, args.port, args.username.readlines(), args.password.readlines())

elif args.sub_command == "redis":
    redis_run(args.host, args.port, args.password.readlines())

elif args.sub_command == "ip":
    run_ip(args.host, args.iface)

elif args.sub_command == "port_a":
    scan_port_a_run(args.host, args.sep)

elif args.sub_command == "port_h":
    scan_port_h_run(args.host)

elif args.sub_command == "ssh":
    ssh_run(args.host, args.port, args.username, args.password.readlines())

elif args.sub_command == "subdomain":
    run_subdomain(args.domain)
else:
    print("请选择要使用的功能")
